<?PHP
    require_once "../aspectos/Seguridad.php";
    $seguridad = Seguridad::getInstance();
    //$seguridad->escapeSQL($_GET);
    header("Content-type: text/xml;charset=utf-8");
    echo "<?xml version='1.0' encoding='utf-8' ?>";
    $page = $_GET['page'];
    $limit = $_GET['rows'];
    $sidx = $_GET['sidx'];
    if ($sidx == "invid")
        $sidx = "horasolicitud";
    $sord = $_GET['sord'];
    require_once "../class/class.Solicitud.php";
    $start = ($page - 1)*$limit;
	$limit1 = ($page *$limit)-1;
	date_default_timezone_set('America/Caracas');
    $solic = new solicitud("",date('Y-m-d'),"","","","","","","","","");
    $result = $solic->solicitudGrid($sord,$sidx,null,null);
    $N = sizeof($result);
	if (($N-$start)<($limit1+1)) $limit2=$N-($limit1+1);
	else $limit2=$limit1;
	//echo $start.'-'.$limit.'-'.$limit1.'-'.$limit2.'-'.$N ;
    $count = $N;
    $total_pages = ceil($N/$limit) ;
    echo "<rows>";
    echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>";
	if ($N>=$limit){
		for ($i=$start; $i<(($N-$start)+$limit); $i++){
			$row = $result[$i];
			echo "<row id='".$i."'>";
			echo "<cell>".$row['idpaciente']."</cell>";
			echo "<cell>".$row['fechasolicitud']."</cell>";
			echo "<cell>".$row['horasolicitud']."</cell>";
			echo "<cell>".$row['tipo']."</cell>";
			echo "<cell>".$row['especialidad']."</cell>";
			echo "<cell>".$row['procedencia']."</cell>";
			echo "<cell>".$row['observaciones']."</cell>";
			$estado = $row['usuarioa'];
			echo "<cell>";
			if ($estado == null)
				echo "No";
			else
				echo "Si";
			echo "</cell>";
			echo "<cell>".$row['usuarior']."</cell>";
			echo "<cell>".$row['hospedaje']."</cell>";
			echo "<cell>".$row['cupoCR']."</cell>";
			echo "</row>";
		}
	} else if ($N<$limit){
		for ($i=$start; $i<$N; $i++){
			$row = $result[$i];
			echo "<row id='".$i."'>";
			echo "<cell>".$row['idpaciente']."</cell>";
			echo "<cell>".date_format($row['fechasolicitud'],"Y-m-d")."</cell>";
			echo "<cell>".$row['horasolicitud']."</cell>";
			echo "<cell>".$row['tipo']."</cell>";
			echo "<cell>".$row['especialidad']."</cell>";
			echo "<cell>".$row['procedencia']."</cell>";
			echo "<cell>".$row['observaciones']."</cell>";
			$estado = $row['usuarioa'];
			echo "<cell>";
			if ($estado == null)
				echo "No";
			else
				echo "Si";
			echo "</cell>";
			echo "<cell>".$row['usuarior']."</cell>";
			echo "<cell>".$row['hospedaje']."</cell>";
			echo "<cell>".$row['cupoCR']."</cell>";
			echo "</row>";
		}
	}
    echo "</rows>";
?>